package org.ktpro.shortlink.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.ktpro.shortlink.admin.common.convention.result.Result;
import org.ktpro.shortlink.admin.common.convention.result.Results;
import org.ktpro.shortlink.admin.remote.dto.ShortLinkFeignRemoteService;
import org.ktpro.shortlink.admin.remote.dto.req.RecycleBinRemoveReqDTO;
import org.ktpro.shortlink.admin.remote.dto.req.RecycleBinReqDTO;
import org.ktpro.shortlink.admin.remote.dto.req.ShortLinkRecycleBinPageReqDTO;
import org.ktpro.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import org.ktpro.shortlink.admin.service.RecycleBinService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 回收站控制层
 */
@RestController(value = "recycleBinControllerByAdmin")
@Slf4j
@RequiredArgsConstructor
public class RecycleBinController {

    private final ShortLinkFeignRemoteService shortLinkFeignRemoteService;

    private final RecycleBinService recycleBinService;

    /**
     * 短链接移进回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinReqDTO requestParam) {
        shortLinkFeignRemoteService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 短链接移出回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinReqDTO requestParam) {
        shortLinkFeignRemoteService.removeRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 回收站彻底删除短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> removeFullyRecycleBin(@RequestBody RecycleBinRemoveReqDTO requestParam) {
        shortLinkFeignRemoteService.removeFullyRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 分页查询回收站短链接
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<Page<ShortLinkPageRespDTO>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
        return recycleBinService.pageRecycleBinShortLink(requestParam);
    }

}
